@extends('admin.layout.common')
@section('content')
    <link rel="stylesheet" type="text/css" href="{{URL::asset('css/user/account.css')}}">
    <div class="content">
        <div class="mon">
            <div class="mon_left">
                <p>
                    <i class="iconfont icon gongzuo">&#xe647;</i>
                    <span>{{date('Y年m月d日')}}  本月已开户{{ session('monthPass') }}个  打回{{session('monthRefuse')}}个</span>
                <p>超过了{{ session('monthPrecent') }}的三咖审核员，继续努力！从此踏上人生巅峰，迎娶白富美！</p>
                </p>
            </div>
            <div class="mon_right">
                <p>您今天已经开户{{session('todayPass')}}个    打回{{session('todayRefuse')}}个</p>
                <p>超过了{{session('todayPrecent')}}的三咖开户员哦~棒棒哒！！！</p>
            </div>
        </div>
        <p class="tongzhi"><i class="iconfont icon laba">&#xe914;</i>{{getArticleByDepartmentId()}}</p>
    <div class="center">
        <h1 class="h1">用户开户中心</h1>
        <p style="font-size:14px;">
            <svg class="icon" aria-hidden="true">
                <use xlink:href="#icon-wenjianjia"></use>
            </svg>
            <span class="now_421">当前待审核共<span class="red">{{session('currentCheck')}}</span>人</span>
            <svg class="icon" aria-hidden="true">
                <use xlink:href="#icon-bijiben"></use>
            </svg>
            <span class="now_159">今日已审核<span class="red">{{session('todayPassAll')}}</span>人</span>
            <svg class="icon" aria-hidden="true">
                <use xlink:href="#icon-qianbi"></use>
            </svg>
            <span class="now_10">我已审核<span class="red">{{session('myCheck')}}</span>人</span>
        </p>
    </div>
    <div class="content_gain">
        <div class="luan">
            <!--button切换-->
            <button type="button" class="audit">审核新用戶</button><button type="button" class="manuallyAdd" style="-webkit-border-radius: 0 10px 10px 0 ;-moz-border-radius: 0 10px 10px 0;border-radius: 0 10px 10px 0;">手工添加新用戶</button>
            <!-- 审核新用户开始-->
            <div class="AccessToContent">
                <div class="btn_box">
                    <div>
                        <button type="button" class="lignqu" style=" display:block" onclick="getTask()">领取任务</button>
                    </div>
                    <div class="btn_status">
                        <button type="button" style=" display:none;"></button>
                        <button type="button" class="daishenhe" onclick=userClientList(6) style="border-left:1px solid #9F1919;"><span style="color:red;">(0)</span>审核中<span></span></button>
                        <button type="button" class="signal" onclick=userClientList(3)><span style="color:red;">(0)</span>信号不好<span></span></button>
                        <button type="button" class="relation" onclick=userClientList(4)><span style="color:red;">(0)</span>稍后联系<span></span></button>
                        <button type="button" class="answer" onclick=userClientList(2)><span style="color:red;">(0)</span>无人接听<span></span></button>
                    </div>
                    <div>
                        <button type="button" onclick="javascrtpt:window.location.href='{{url('admin/userPhoneTime')}}'" class="btn_tesk">音乐人统计</button>
                    </div>
                </div>
                <!--<div class="shenheyonghu">-->
                <!-- 审核新用户左边-->
                <div class="gainContent_left"  style="display: flex;">
                    <div class="tablebox">
                        <table style="display:block;" class="active" border="1px" id="task">
                            <tr>
                                <th style="color:red;" class="th">申请时间</th>
                                <th class="th">ID</th>
                                <th class="th">性质</th>
                                <th class="th">地区</th>
                                <th class="th">状态</th>
                            </tr>
                        </table>
                    </div>
                    <!-- 审核新用户右边-->
                    <div class="new_user" style="">
                        <p class="p1">
                            <span class="xiugai">修改用户信息</span>
                            <span style="font-weight:bold">用户开户审核编辑</span>
                            <span>用户来源：<span class="detail10">360引擎</span></span>
                        </p>
                        <div class="message">
                            <div class="message_left">
                                <p style="text-align: right;display:block;">客户预留信息</p>
                                <p><span for="">期望联络时间</span><span for="" class="detail1"></span></p>
                                <p><span for="">主要专业</span><span for="" class="detail2"></span></p>
                                <p><span for="">真实姓名</span><span for="" class="detail3"></span></p>
                                <p><span for="">艺名</span><span for="" class="detail4"></span></p>
                                <p><span for="">国家</span><span for="" class="detail5"></span></p>
                            </div>
                            <div class="message_left">
                                <p style="text-align: right;display:block;">客户预留信息</p>
                                <p><span for="">所在省份</span><span for="" class="detail6"></span></p>
                                <p><span for="">手机号码</span><span for="" class="detail7"></span></p>
                                <input class="forCall" type="hidden">
                                <p><span for="">百度度百科</span><span for="" class="detail8"></span></p>
                                <p><span for="">已发表作品链接</span><span for="" class="detail9"></span></p>
                            </div>
                        </div>
                        <div class="modification">
                            <button id="dialout" type="button" class="layui-btn layui-btn-radius phone_status1" onclick="phoneCall(this)">电话接通</button>
                            <button type="button" class="layui-btn layui-btn-warm layui-btn-radius pink phone_status2">无人接听</button>
                            <button type="button" class="layui-btn layui-btn-warm layui-btn-radius pink phone_status3">信号不好</button>
                            <button type="button" class="layui-btn layui-btn-danger layui-btn-radius phone_status4">稍后联络</button>
                            <button type="button" class="layui-btn layui-btn-warm layui-btn-radius red phone_status5">查无此人</button>
                            <div>
                                <button type="button" class="pingjia pingjia1 layui-btn layui-btn-danger layui-btn-radius">信息完善</button>
                                {{--<button type="button" class="layui-btn layui-btn-normal layui-btn-radius make_file">生成协议并发送</button>--}}
                            </div>
                        </div>
                    </div>
                    <!--</div>-->
                </div>
            </div>
            <!--手动添加新用户开始-->
            <div class="AccessToContent_add" style="display:none;">
                <form id="subForm" action="{{url('admin/addClientUser')}}" method="post" enctype="multipart/form-data">
                    {{csrf_field()}}
                <div class="gainContent_right">
                    <p style="font-weight:bold;font-size:16px;">用户开户审核编辑</p>
                    <!--手动添加新用户中间-->
                    <div class="gainContent_right_center">
                        <div class="gainContent_right_center_left">
                            <div class="xinxileft">
                                <p>&nbsp;</p>
                                <p><label for="">所期望时间</label></p>
                                <p><label for="">主要专业</label></p>
                                <p><label for="">真实姓名</label></p>
                                {{--<p><label for="">登录用户名</label></p>--}}
                                <p><label for="">艺名</label></p>
                                <p><label for="">百度百科</label></p>
                                <p><label for="">国家</label></p>
                            </div>
                            <div class="xinxiright">
                                <p>客户信息</p>
                                <p><select name="phone_time">
                                        <option value="1">10：00-12：00</option>
                                        <option value="2">13：00-17：00</option>
                                        <option value="3">18：00-23：00</option>
                                        <option value="4">不限时间</option>
                                    </select></p>
                                <p><select name="major">
                                        <option value="1">原唱歌手</option>
                                        <option value="2">歌手</option>
                                        <option value="3">乐手</option>
                                        <option value="4">词作者</option>
                                        <option value="5">曲作者</option>
                                    </select></p>
                                <p><input type="text" placeholder="请输入真实姓名" name="real_name" required></p>
                                {{--<p><input type="text" placeholder="登录用户名" name="user_name" required></p>--}}
                                <p><input type="text" placeholder="请输入艺名" name="stage_name"></p>
                                <p><input type="text" placeholder="请输入" name="baidu"></p>
                                <p><select name="country">
                                        <option value="中国">中国</option>
                                        <option value="港澳台">港澳台</option>
                                    </select>
                                    <select name="provice">
                                        <option value="">--请选择--</option>
                                        <option value ="北京市">
                                            北京市 </option><option value ="天津市">
                                            天津市 </option><option value ="上海市">
                                            上海市 </option><option value ="重庆市">
                                            重庆市 </option><option value ="河北省">
                                            河北省 </option><option value ="山西省">
                                            山西省 </option><option value ="辽宁省">
                                            辽宁省 </option><option value ="吉林省">
                                            吉林省 </option><option value ="黑龙江省">
                                            黑龙江省</option><option value ="江苏省">
                                            江苏省 </option><option value ="浙江省">
                                            浙江省 </option><option value ="安徽省">
                                            安徽省 </option><option value ="福建省">
                                            福建省 </option><option value ="江西省">
                                            江西省 </option><option value ="山东省">
                                            山东省 </option><option value ="河南省">
                                            河南省 </option><option value ="湖北省">
                                            湖北省 </option><option value ="湖南省">
                                            湖南省 </option><option value ="广东省">
                                            广东省 </option><option value ="海南省">
                                            海南省 </option><option value ="四川省">
                                            四川省 </option><option value ="贵州省">
                                            贵州省 </option><option value ="云南省">
                                            云南省 </option><option value ="陕西省">
                                            陕西省 </option><option value ="甘肃省">
                                            甘肃省 </option><option value ="青海省">
                                            青海省 </option><option value ="广西壮族自治区">
                                            广西壮族自治区</option><option value ="内蒙古自治区">
                                            内蒙古自治区</option><option value ="西藏自治区">
                                            西藏自治区</option><option value ="宁夏回族自治区">
                                            宁夏回族自治区 </option><option value ="新疆维吾尔自治区">
                                            新疆维吾尔自治区</option>
                                    </select>
                                </p>
                            </div>
                        </div>
                        <div class="gainContent_right_center_right">
                            <div class="xinxileft">
                                <p>&nbsp;</p>
                                <p><label for="">手机号码</label></p>
                                <p><label for="">收款人姓名</label></p>
                                <p><label for="">银行卡</label></p>
                                <p><label for="">开户行信息</label></p>
                                <p><label for="">已发作品链接</label></p>
                            </div>
                            <div class="xinxiright">
                                <p>客户信息</p>
                                <p><input type="text" placeholder="请输入手机号" name="phone" required></p>
                                <p><input type="text" placeholder="请输入收款人姓名" name="payee_name" required></p>
                                <p><input type="text" placeholder="请输入银行卡号" name="band_card" required></p>
                                <p><input type="text" placeholder="请输入开户行" name="band_info" required></p>
                                <p><input type="text" placeholder="请输入作品链接" name="links"></p>
                            </div>
                        </div>
                    </div>
                    <div class="gainContent_right_bottom">
                        <textarea name="remark" cols="30" rows="10" placeholder="客服备注客户信息"></textarea>
                        <div class="gainContent_right_bottom_right">
                            <p>
                                <label for="">签约人身份证：</label>
                                <input type="text" placeholder="请输入身份证号" name="card" required>
                                <select name="sign_type">
                                    <option value="1">全球独家</option>
                                    <option value="2">中国大陆独家</option>
                                    <option value="3">中国地区独家</option>
                                    <option value="4">外海（含港澳台）独家</option>
                                    <option value="5">海外（不含港澳台）独家</option>
                                    <option value="6">欧洲独家</option>
                                    <option value="7">亚洲独家</option>
                                    <option value="8">美洲独家</option>
                                    <option value="9">非洲独家</option>
                                </select>
                                <select name="sign_time" required>
                                    <option value="">签约期限</option>
                                    <option value="3">3年自动续约</option>
                                    <option value="2">2年自动续约</option>
                                    <option value="1">1年自动续约</option>
                                    <option value="4">自由艺人</option>
                                </select>
                            </p>
                            <p>
                                <label for="">指定代理：</label>
                                <select name="software_id" id="">
                                    <option>--请选择--</option>
                                    <option value="无">无代理</option>
                                    @foreach($agent as $v)
                                        <option value="{{$v['software_id']}}">{{$v['simple_name']}}</option>
                                    @endforeach
                                </select>
                                <label for="">用户协议：</label>
                                <input type="file" class="upload_file" name="agreement" onchange="doChange(this)" style="display:none;"/>
                                <input class="photoCover" maxlength="0" placeholder="请上传协议" type="text" required>
                                <input type="button" onclick="$('input[class=upload_file]').click();" class="mybutton" value="浏览" style="width:80px;margin:0 10px;cursor:pointer;"/>
                            </p>
                            <button type="submit" value="" class="btn">发送账户密码</button>
                        </div>
                    </div>
                    </div>
                </form>
                </div>
            </div>
        </div>
    </div>
    <script src="{{asset('js/user/account.js')}}"></script>
    <script>
      statistics();

      //查看各个状态下用户数量
      // signal relation answer
      function statistics() {
        $("#task tr:gt(0)").remove();
          $.get('http://{{$_SERVER['HTTP_HOST']}}/admin/userClientList/'+6, function (data) {
              let num = 0;
              if(data[0]['id']) {
                  num = data.length;
              }
              let html = '<span style="color:red;">('+ num +')</span>审核中';
              $('.daishenhe').html(html)
          })

        $.get('http://{{$_SERVER['HTTP_HOST']}}/admin/userClientList/'+3, function (data) {
          let num = 0;
          if(data[0]['id']) {
            num = data.length;
          }
          let html = '<span style="color:red;">('+ num +')</span>信号不好';
          $('.signal').html(html)
        })

        $.get('http://{{$_SERVER['HTTP_HOST']}}/admin/userClientList/'+4, function (data) {
          let num = 0;
          if(data[0]['id']) {
            num = data.length;
          }
          let html = '<span style="color:red;">('+ num +')</span>稍后联系';
          $('.relation').html(html)
        })

        $.get('http://{{$_SERVER['HTTP_HOST']}}/admin/userClientList/'+2, function (data) {
          let num = 0;
          if(data[0]['id']) {
            num = data.length;
          }
          let html = '<span style="color:red;">('+ num +')</span>无人接听';
          $('.answer').html(html)
        })
      }

      //领取任务
      function getTask() {
        $("#task tr:gt(0)").remove();
        $('.btn_status').children("button").css('color','#CF2121');
        $('.btn_status').children("button").css('background','#fff');
        $.get('http://{{$_SERVER['HTTP_HOST']}}/admin/userGetTask', function (data) {
          if(data[0]['id']) {
            var tr = '';
            for (var i = 0; i < data.length; i++) {
              tr += "<tr onclick=detail(" + data[i]['id'] + ") id=tr"+ data[i]['id'] +"><td>" + data[i]['create_at'] + "</td><td>" + data[i]['id'] + "</td><td>" + data[i]['type'] + "</td><td>" + data[i]['provice'] + "</td><td>" + data[i]['status'] + "</td></tr>"
            }
          }else{
            tr = '<tr><td>无任务</td></tr>';
          }
          $('#task').append(tr);
        })
      }

      //用户详情
      function detail(id){
        $('.pingjia1').unbind("click").click(function(){
          pingjia1(id);
        });
        $('.make_file').unbind("click").click(function(){
           makeFile(id);
        });
        // $('.phone_status1').unbind("click").click(function(){
        //     phoneStatus(id,1);
        // });
        $('.phone_status2').unbind("click").click(function(){
          phoneStatus(id,2);
        });
        $('.phone_status3').unbind("click").click(function(){
          phoneStatus(id,3);
        });
        $('.phone_status4').unbind("click").click(function(){
          phoneStatus(id,4);
        });
        $('.phone_status5').unbind("click").click(function(){
          phoneStatus(id,5);
        });
        $('.xiugai').attr('id',id);
        $("#task tr").css('background','#fff');
        $("#task tr").css('color','black');
        $.get('http://{{$_SERVER['HTTP_HOST']}}/admin/userClientDetail/'+id,function(data){
          if(data[0]['id']) {
            $(".detail1").text(data[0]['phone_time_text']);
            $(".detail2").text(data[0]['major_text']);
            $(".detail3").text(data[0]['real_name']);
            $(".detail4").text(data[0]['stage_name']);
            $(".detail5").text(data[0]['country']);
            $(".detail6").text(data[0]['provice']);
              var str=data[0]['phone'];
              var str2 = str.substr(0,3)+"****"+str.substr(7);
            $(".detail7").text(str2);
            $('.forCall').val(str);
            $(".detail8").text(data[0]['baidu']);
            $(".detail9").text(data[0]['links']);
            $(".detail10").text(data[0]['come_from']);
            $("#tr"+id).css('background','rgb(159, 25, 25)');
            $("#tr"+id).css('color','#fff');
          }
        })
      }

      //审核评价
      function pingjia1(id){
        layer.open({
          type: 2,
          anim:5,
          area:['1000px','600px'],
          shade:['0.5','#ccc'],
          content: 'http://{{$_SERVER['HTTP_HOST']}}/admin/checkClientUser/'+id
          ,end:function(){
            userClientList(6);
            $('.pingjia1').unbind("click");
            $('.xiugai').attr('id','');
            $('.pingjia').on('click',function(){
                layer.msg('请选择审核用户');
            });
          }
        });
      }

      //根据phone_status帅选用户
      function userClientList(id) {
        $("#task tr:gt(0)").remove();
        $.get('http://{{$_SERVER['HTTP_HOST']}}/admin/userClientList/'+id, function (data) {
          if(data[0]['id']) {
            var tr = '';
            for (var i = 0; i < data.length; i++) {
              tr += "<tr onclick=detail(" + data[i]['id'] + ") id=tr"+ data[i]['id'] +"><td>" + data[i]['create_at'] + "</td><td>" + data[i]['id'] + "</td><td>" + data[i]['type'] + "</td><td>" + data[i]['provice'] + "</td><td>" + data[i]['status'] + "</td></tr>"
            }
          }else{
            tr = '<tr><td>无任务</td></tr>';
          }
          $('#task').append(tr);
        })
      }

      //更改phone_status
      function phoneStatus(id,status){
        $.get('http://{{$_SERVER['HTTP_HOST']}}/admin/updatePhoneStatus/'+id+'/'+status,function(data){
          if(data['code'] == 200) {
            layer.open({
              content: '修改成功'
              ,end:function(){
                //userClientList(6);
                    $('#tr'+id).remove();
              }
            });
          }
        })
      }

      //正在审核的用户
      function checking(){
        $("#task tr:gt(0)").remove();
        $.get('http://{{ $_SERVER['HTTP_HOST'] }}/admin/userClientList', function (data) {
          if(data[0]['id']) {
            var tr = '';
            for (var i = 0; i < data.length; i++) {
              tr += "<tr onclick=detail(" + data[i]['id'] + ") id=tr"+ data[i]['id'] +"><td>" + data[i]['create_at'] + "</td><td>" + data[i]['id'] + "</td><td>" + data[i]['type'] + "</td><td>" + data[i]['provice'] + "</td><td>" + data[i]['status'] + "</td></tr>"
            }
          }else{
            tr = '<tr><td>无任务</td></tr>';
          }
          $('#task').append(tr);
        })
      }

      //预览功能
      function doChange(file){
        var upload_file = $.trim($(".upload_file").val());    //获取上传文件
        $('.photoCover').val(upload_file);     //赋值给自定义input框
      }

      //电话接通
      function phoneCall(obj) {
        if (!$('.detail7').html()) {
          layer.msg('请选择用户')
          return
        }
        obj.innerHTML = '正在接通';
        obj.setAttribute('disabled', 'disabled')
        $.ajax({
          url: '{{url('/admin/dialout')}}',
          method: 'POST',
          data: {
            _token: '{{csrf_token()}}',
            Exten: $('.forCall').val()
          },
          success: function (data) {
            let res = JSON.parse(data)
            if (res.Succeed == false) {
              if(res.Message === '407 Agent can not take calls'){
                layer.msg('坐席未登录')
              }
              obj.innerHTML = '无法接通'
              obj.removeAttribute('disabled')
              setTimeout(function(){
                obj.innerHTML = '电话接通'
              }, 5000)
            } else if(res.Succeed == true) {
              obj.innerHTML = '接通成功'
              obj.removeAttribute('disabled')
            }
          }
        })
      }

      //电话接通
      //Authorization 转码前 '{{'N00000035358'.':'.date('YmdHis', time())}}'
      //sig md5前 '{{'N00000035358'.'357c32e0-d5bc-11e8-b80f-9b6791ff9165'.date('YmdHis', time())}}'
        {{--function phoneCall() {--}}
        {{--$.ajax({--}}
        {{--headers: {--}}
        {{--'Accept': 'application/json',--}}
        {{--'Content-Type': 'application/json;charset=utf8',--}}
        {{--'Authorization': '{{base64_encode('N00000035358'.':'.date('YmdHis', time()))}}',--}}
        {{--},--}}
        {{--url: 'http://apis.7moor.com/v20160818/call/dialout/N00000035358?sig=' + '{{strtoupper(md5('N00000035358'.'357c32e0-d5bc-11e8-b80f-9b6791ff9165'.date('YmdHis', time())))}}',--}}
        {{--method: 'POST',--}}
        {{--async:false,--}}
        {{--data: {--}}
        {{--'FromExten': '8000',--}}
        {{--'Exten': '15038238593'--}}
        {{--},--}}
        {{--dataType: 'json',--}}
        {{--success: function success(data) {--}}
        {{--console.log(data)--}}
        {{--}--}}
        {{--});--}}
        {{--}--}}



    </script>
@endsection


